package disjunction.examples.blitting
{
	import disjunction.core.*;
	import disjunction.extensions.view.BlitterViewConfig;
	
	import flash.geom.Point;
	
	[SWF(width="550", height="400", backgroundColor="#000000", frameRate="500")]
	
	/**
	 * States Example.
	 *
	 * @author Nick Wiggill
	 */
	
	public class BlittingDemo extends Game
	{
		//Update periods for View and Controller. One should be an integer multiple of
		//the other to avoid jerky-looking motion. View is usually quicker.
		public const CONTROLLER_PERIOD_MS:uint = 100; //10FPS
		public const VIEW_PERIOD_MS:uint = 20; //50FPS
		
		//If application loses processor focus, limit the max timedelta.
		public const UPDATE_TIMEOUT_MS:uint = 500;
		
		//pixel dimensions of view
		public const WIDTH:Number = 225;
		public const HEIGHT:Number = 200;
		//pixel scaling
		public const PIXEL_SCALE:Number = 2;
		
		public function BlittingDemo()
		{
			//Register at least one game state for execution.
			//Note how we can use a dynamic object as the model here.
			registerState( new GameState("Demo",
				{position: new Point(50, 50), motion: new Point(100, 50), radius: 7},
				new DemoView(),
				new DemoController()) );

			//Prepare configuration.
			var config:GameStateConfiguration = new GameStateConfiguration();
			config.view = new BlitterViewConfig(VIEW_PERIOD_MS, UPDATE_TIMEOUT_MS, this, WIDTH, HEIGHT, PIXEL_SCALE);
			config.controller =	new ControllerConfiguration(VIEW_PERIOD_MS, UPDATE_TIMEOUT_MS);
			
			//Use configuration to initialise and potentially begin execution of 
			//starting gamestate. Configuration of view and controller are separate from
			//construction, as states may be configured anew when reactivated for reuse.
			initialise("Demo", config);
		}
	}
}